<?php
	/**
	 *	Copyright (c) TeamFlamingo And gray 2004-2009
	 *	www.me-live.com.cn / www.i-gray.cn
	 *
	 *	[ WARNING ]
	 *		This is NOT a freeware!
	 *		You MUST get author's authorization before using it!
	 *	[ WARNING ]
	 *
	 *	Name : cache.h.php / Development Code Evolve
	 *	Created / Modify : 2010-2-17 / --
	 */

	if( !defined( 'IN_TEAME' ) )
	{
		exit( 'Access Denied' );
	}

	//$forumTopsArray	=	$boardTopsArray	=	array();
	function	getTopsData ( /*$forum*/ )
	{
		global	$db;//, $forumTopsArray, $boardTopsArray;
		$postsBgcolor	=	$postsForumBgcolor	=	'#efefef';
		$postsTopsResult	=	$db->query( "SELECT `p`.`tid`, `p`.`title`, `p`.`lastReplyUid`, `p`.`timestamp`, `p`.`mid`, `p`.`read`, `p`.`reply`, `p`.`lastTimestamp`, `p`.`type`, `m`.`uid`, `m`.`author`, `u`.`username` as `replyUsername` FROM `mdk_posts` as `p`, `mdk_member` as `m`, `mdk_users` as `u` WHERE `type` != '0' AND `child` = '0' AND `p`.`uid` = `m`.`uid` AND `p`.`lastReplyUid` = `u`.`uid`" );

		while( $row = $db->assoc( $postsTopsResult ) )
		{
			$row['topstype']	= /*$row['type'] == 1 ? */'社区置顶';// : '板块置顶';
			$row['topsclass']	= /*$row['type'] == 1 ? */'forum_top';// : 'board_top';
			$row['date']		= date( "Y-m-d", $row['timestamp'] );
			$row['lastTimestamp']	=	$row['lastTimestamp'] ? $row['lastTimestamp'] : $row['timestamp'];
			$row['lastReplyTime']	=	date( "Y-m-d h:i:s", $row['lastTimestamp'] );
			//	[CH]	获取最后回复人
			$row['replyUsername']	=	$row['reply'] == 0 && $row['lastReplyUid'] == $row['uid'] ? '' : $row['replyUsername'];

			//if( $row['type'] == 1 )
			//{
				$row['bgcolor']		= $postsForumBgcolor	= $postsForumBgcolor == '#efefef' ? '#fff' : '#efefef';
				$forumTopsArray[]	= $row;
			/*}
			else
			{
				$row['bgcolor']		= $postsBgcolor	= $postsBgcolor == '#efefef' ? '#fff' : '#efefef';
				$boardTopsArray[]	= $row;
			}*/
		}
		return	$forumTopsArray;
		//return	$forum ? $forumTopsArray : $boardTopsArray;
	}

	function	getForumtopCache ()
	{
		//global	$forumTopsArray;
		$forumTopsArray	=	getTopsData();
		$string	=	'';
		$i		=	0;
		$json	=	json_encode( $forumTopsArray );
		@file_put_contents( ME_FORUMTOP_CACHE_FILE, "<?php\nif( !defined( 'IN_TEAME' ) )\n{\n\texit( 'Access Denied' );\n}\n?>\n" . $json );
		return	ME_FORUMTOP_CACHE_FILE;
	}
?>